package com.mvp.shq.washer.ui.shop.categoryPage;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.adapter.CategoryAdapter;
import com.mvp.shq.washer.base.BaseFragment;
import com.mvp.shq.washer.entity.shop.Brand;
import com.mvp.shq.washer.entity.shop.ShopProductJump;
import com.mvp.shq.washer.utils.JumpUtil;
import com.mvp.shq.washer.utils.RecyclerViewDivider;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class CategoryFragment extends BaseFragment<Presenter, Model> implements CategoryPageConstract.View {


    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    private String categoryId;
    private List<Brand> brands;
    public CategoryFragment(String categoryId){
        this.categoryId = categoryId;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_category;
    }

    @Override
    public void initView() {
        recyclerview.setLayoutManager(new GridLayoutManager(context,4));
        RecyclerViewDivider divider = new RecyclerViewDivider(context, LinearLayoutManager.VERTICAL, 5, ContextCompat.getColor(context, R.color.shop_divison_bg));
        recyclerview.addItemDecoration(divider);
        presenter.getBrands(categoryId);
    }

    @Override
    public void getBrandsS(List<Brand> list) {
        if (list == null){
            return;
        }
        brands = list;
        CategoryAdapter adapter = new CategoryAdapter(context,brands, new CategoryAdapter.OnCategoryItemClickLinstener() {
            @Override
            public void onClick(int position) {
                ShopProductJump params = new ShopProductJump();
                params.setType(ShopProductJump.PRODUCT_TYPE_CATEGORY);
                params.setTitle(brands.get(position).getBrandName());
                params.setCategoryId(categoryId);
                JumpUtil.toProductList(context,params);
            }
        });
        recyclerview.setAdapter(adapter);
    }
}
